package com.sx.pipeline.utils;

import com.sx.mvvmlibs.utils.Logs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @Author: YY
 * @Date: 2022/4/21
 * @Description: TODO
 */
public class DXFHelper {

    private BufferedReader bReader;
    private String temp1,temp2,temp3,temp4,temp5,temp6,temp7;

    public void parseDxf(File file) {
        if (!file.exists()) {
            System.out.println("File Not Exist");
            return;
        }
        try {
            bReader = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("Begin read file" + file.getName());
        // 从DXF文件中读取一个字符
        temp1 = readString(bReader);
        // 未到文件结束标志
        while (!"EOF".equals(temp1)) {
            temp1 = readString(bReader);
            Logs.d("parseDxf "+temp1);
            // 实体段开始
            if ("ENTITIES".equals(temp1)) {
                temp2 = readString(bReader);
                Logs.d("parseDxf "+temp2);
                while (true) {

                }
            }
        }
    }

    private String readString(BufferedReader datain) {
        String temp = null;
        try {
            temp = new String(datain.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
        ChangeCharset test = new ChangeCharset();
        try {
            temp = test.toUTF_8(temp);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return temp;
    }
}
